<?php

namespace Auth\Permissions;

use Zend\Mvc\MvcEvent;
use Zend\EventManager\EventManagerInterface;
use Zend\Event\EventManager\ListenerAggregateInterface;
use Zend\Permissions\Acl\Acl;
use Zend\Permissions\Acl\Role\GenericRole as Role;
use Zend\Permissions\Acl\Resource\GenericResource as Resource;

class AclListener implements ListenerAggregateInterface{
    protected $listeners=array();
    public function attach(EventManagerInterface $events, $priority=100){
        $this->listeners[]=$events->attach(MvcEvent::EVENT_DISPATCH,array($this,'onDispatch'),$priority);
        
    }
    public function detach(EventManagerInterface $events){
        foreach($this->listeners as $index=>$listener){
            if($events->detach($listener)){
                unset($this->listeners[$index]);
            }
        }
    }
    public function onDispatch(MvcEvent $e){
        $acl=new Acl();
        $acl->addRole(new Role('invitado'))
                ->addRole(new Role('Administrador'));
        $acl->addResource(new Resource('prueba:index'));
        
    }
}